home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
JCSM Shareware Collection 1996 September
/
JCSM Shareware Collection (JCS Distribution) (September 1996).ISO
/
gameothr
/
wordy411.zip
/
SUFFIX.C
< prev
next >
Wrap
C/C++ Source or Header
|
1995-12-17
|
7KB
|
241 lines
/**************************************************************************/
/* Suffix Utility */
/* */
/* M\Cooper */
/* 3425 Chestnut Ridge Rd. */
/* Grantsville, MD 21536-9801 */
/* -------------------------- */
/* Email: thegrendel@aol.com */
/* */
/* $2.00 to register the entire WORDY package */
/* */
/**************************************************************************/
#include <conio.h>
#include "srch.h"
#define FILE_OPENING_ERROR 3
#define FILENAME_MAXLEN 8
#define CR "\n"
#define FILE_SUFFIX ".suf"
#define MAXLEN 30
#define LINE_LEN 80
#define NOARGS 1
#define INCREMENT 1
#define WD 10
#define SPACE ' '
#define BUFFERSIZE 8192
char ad[] =
"SUFFIX utility by M\\Cooper, 3425 Chestnut Ridge Rd., Grantsville, MD 21536";
typedef enum { FALSE, TRUE } Boolean;
void getword( char *lset, char *filenam );
void center( char *strng );
Boolean wordtest( char *lset, char *wd, size_t len );
void main( int argc, char **argv )
{
char letterset[ MAXLEN ],
filename [ MAXLEN ];
if( argc == NOARGS )
{
clrscr();
puts("Enter a LETTERSET to test ... ");
gets( letterset );
strcpy( filename, "word.lst" );
}
else
if( argc == NOARGS + 1 )
{
strcpy( letterset, *( argv + 1 ) );
strcpy( filename, "word.lst" );
}
else
{
strcpy( letterset, *( argv + 1 ) );
strcpy( filename, *( argv + 2 ) );
}
getword( letterset, filename );
}
/**********************************WORDTEST********************************/
/* Function tests if word is constructible from Letterset */
/* Args in: char *letterset, char *word */
/* Returns: error_flag == TRUE (1) if constructible, FALSE (0) if not */
/**************************************************************************/
Boolean wordtest( char *letterset, char *word, size_t l_len )
{
Boolean error_flag;
if( !strncmp( letterset, word + strlen( word ) - 1 - l_len, l_len ) )
error_flag = TRUE;
else
error_flag = FALSE;
return( error_flag );
}
/*************************************************************/
void getword( char *letter_set, char *filename )
{
char l_set [ MAXLEN ],
word [ MAXLEN ],
tempstr [ MAXLEN + 1 ],
targetfile [ MAXLEN ],
bar [ LINE_LEN + 1 ],
double_bar [ LINE_LEN + 1 ],
msg1 [ WD ],
msg2 [ WD ];
size_t l_len;
FILE *fptr,
*tfile;
int fnamelen;
long wcount = 0L;
l_len = strlen( letter_set );
memset( bar, '-', LINE_LEN );
*( bar + LINE_LEN ) = NULL;
memset( double_bar, '=', LINE_LEN );
*( double_bar + LINE_LEN ) = NULL;
/*************opening credits*************/
clrscr();
printf( double_bar );
strcpy( tempstr, ad );
center ( tempstr );
printf( tempstr );
printf( CR );
printf( double_bar );
printf( CR );
/****************************************/
strcpy ( l_set, letter_set );
// strcat ( letter_set, CR );
/* Create name of file to store derived words in */
/*********************************************************/
fnamelen = strlen( l_set );
if( fnamelen > FILENAME_MAXLEN )
fnamelen = FILENAME_MAXLEN;
strncpy( targetfile, l_set, fnamelen );
*( targetfile + fnamelen ) = NULL;
//NULL-terminate string, so strcat works, ha, ha.
strcat( targetfile, FILE_SUFFIX );
/*********************************************************/
if( !( fptr = fopen( filename, "rt" ) ) )
{
printf( "\7\7\7Cannot open Wordfile!" );
exit( FILE_OPENING_ERROR );
}
if( setvbuf( fptr, NULL, _IOFBF, 2 * BUFFERSIZE ) )
exit( FILE_OPENING_ERROR + 1 );
if( !( tfile = fopen( targetfile, "wt" ) ) )
{
printf( "\7\7\7Cannot open file to save words in!" );
exit ( FILE_OPENING_ERROR + 2 );
}
if( setvbuf( tfile, NULL, _IOFBF, BUFFERSIZE ) )
exit( FILE_OPENING_ERROR + 3 );
/**************'Wait' Message************/
printf( CR CR );
printf( "WORKING...\n\n" );
printf( "This will take a few seconds...\n" );
printf( "Please be patient.\n\n" );
printf(
"Now searching 100,000+ word file \nand writing file of valid words suffixed -%s-.\n\n",
letter_set );
/*****************************************/
sprintf( tempstr, "Word(s) generated with suffix: %s\n", strupr( l_set ) );
center( tempstr );
fprintf( tfile, double_bar );
fprintf( tfile, CR );
fprintf( tfile, tempstr );
fprintf( tfile, double_bar );
fprintf( tfile, CR );
/*********************Main Loop*************/
while( fgets( word, MAXLEN, fptr ) != NULL )
if( wordtest( letter_set, word, l_len ) )
{
fprintf( tfile, "%s", word );
wcount++;
}
/*******************************************/
if( wcount == INCREMENT )
{
strcpy( msg1, "word" );
strcpy( msg2, "has" );
}
else
{
strcpy( msg1, "words" );
strcpy( msg2, "have" );
}
fprintf( tfile, bar );
fprintf( tfile, CR );
sprintf( tempstr, "%ld %s suffixed %s %s been found.",
wcount, msg1, l_set, msg2 );
center( tempstr );
fprintf( tfile, tempstr );
fprintf( tfile, "\n\n" );
center( ad );
fprintf( tfile, ad );
fcloseall();
sprintf( tempstr,
"The file %s has %ld %s suffixed by %s\7.",
targetfile, wcount, msg1, l_set );
center( tempstr );
printf( CR CR );
printf( tempstr );
}
void center( char *str )
{
int padding;
char st [ LINE_LEN + INCREMENT ];
padding = LINE_LEN / 2 - strlen( str ) / 2;
memset( st, SPACE, padding );
*( st + padding ) = NULL; //Terminate string
strcat( st, str );
strcpy( str, st );
return;
}